package com.daffodil.util;

import java.io.Serializable;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;

import com.daffodil.util.sequence.Sequence;

/**
 * -雪花算法ID生成器
 * @author yweijian
 * @date 2022年2月17日
 * @version 1.0
 * @description
 */
public class SnowflakeIdentifierGenerator implements IdentifierGenerator, Configurable{

	private final Sequence sequence = new Sequence(1L);
	
	@Override
	public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
		
	}

	@Override
	public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
		return sequence.nextId();
	}

}

